<%= GMap.header %> 
<h1>Post New Story</h1>
<%= error_messages_for :story %>


<table width="100%">
	<tr>
		<td with="50%" valign="top">
			<%= render :partial => 'available_expeditions' %>
		</td>
		<td with="50%" valign="top">
			<fieldset>
				<legend>
					My Teams: 
				</legend>				
				<%= render :partial => "member_of", :object => current_user %>												
			</fieldset>
		</td>
	</tr>
</table>		



<% form_for(:story, :url => user_stories_path(current_user)) do |f| %>
<div id="main">
	<div id="expedition-id">
		<%= f.hidden_field :expedition_id, :value => "" %>
	</div>
	
	<!-- code between these comments is redundant with expeditions controller has to be rafactored into a reusable component     -->
	<div id="location" class="description">
		<p>
			<table>
				<tr>
					<td>		
						<div id="location_name">
							<%=@geo_location.name%>
						</div>

								<%map = GMap.new("map")%>
								<%
								map.control_init(:large_map => true,:map_type => true)							    
								map.set_map_type_init(GMapType::G_HYBRID_MAP)      							
								map.center_zoom_init([@geo_location.lat,@geo_location.lng],8)  	  						
								marker = GMarker.new([@geo_location.lat, @geo_location.lng], :title => @geo_location.name)  
								map.overlay_init marker							
								%>								
								<%= map.div(:width => 400, :height => 400) %>							
								<%= map.to_html %>

						<%= f.hidden_field :geo_location_id, :value => @geo_location.id %>
						<%= error_message_on @story, :geo_location_id -%>
					</td>
					<td valign="top" id="recent-locations">
						<label>
							choose from my recent locations:					
						</label>
						<% @recent_geo_locations.each do |recent_location| %>
							<br>
							<%= link_to_remote recent_location.name, :url => {:action => :select_location, :id => recent_location.id } %>
						<%end%>
					</td>
					<td valign="top" class="description" id="existing-locations">
						<%= link_to image_tag ("add.gif", :border => 0), { :controller => "geo_locations", :action => "new" }%>
						<%= link_to "or add a new location", { :controller => "geo_locations", :action => "new", :return => "story" }%>
						<br/>
						<label>
							or search for existing location:
						</label>
						<%= text_field_with_auto_complete :geo_location, :name, { :size => 25 }, :skip_style => false, :after_update_element => 
						"function(element,value) " +
						  "{ " +			
						remote_function(:update=>'full_name',:url=>{:action=>:complete_location},:with=>"'id='+element.value") + "}"
						 -%>
					</td>
				</tr>
			</table>
		</p>
	</div>
	<!-- code between these comments is redundant with expeditions controller has to be rafactored into a reusable component     -->

	<div id="date" class="description">
		<p>
			<label>When:</label>
			<%= calendar_date_select_tag "story[cleaning_at]", @story.cleaning_at ? @story.cleaning_at.to_s(:date_time12):nil, :embedded => false, :time => true, :buttons => true %>
			<%= error_message_on @story, :cleaning_at -%>	
		</p>
	</div>

	<div id="weight" class="description">
		<p>
			<label>Weight:</label>
			<%= f.text_field :weight %> 
			<%= error_message_on @story, :weight -%>
		</p>
	</div>
	<div id="story" class="description">
		<label>
			Story:
		</label>			
		<p>			
			<%= f.text_area :blog, :rows => 25, :cols => 80 %>			
		</p>
	</div>
</div>

	
<p class="description"><%=submit_tag "Post"%><%= link_to 'back', user_stories_path(current_user)%></p>
</div>
<%end%>
